﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Reflection;


namespace NLE
{
    public partial class ImageAdd : Form
    {
        public MainForm mainForm { get; set; }

        String tempName = String.Empty;

        String tempFilename = String.Empty;

        public ImageAdd()
        {
            InitializeComponent();

            // Also, update our group select box
            //cmbGroup.Items.Add(cmbGroup.Text);


        }

        public void UpdateGroups()
        {
            
            foreach (TreeNode Node in mainForm.treeImages.Nodes)
            {
                cmbGroup.Items.Add(Node.Name);
            }
        }

        private void btnOpenImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            //// Default to the directory which contains our content files.
            //string assemblyLocation = Assembly.GetExecutingAssembly().Location;
            //string relativePath = Path.Combine(assemblyLocation, "../../../../Content");
            //string contentPath = Path.GetFullPath(relativePath);

            //fileDialog.InitialDirectory = contentPath;

            fileDialog.Title = "Load Image";

            //BMP, GIF, EXIF, JPG, PNG and TIFF
            fileDialog.Filter =
                "Image Files(*.BMP;*.JPG;*.GIF;*.TIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.TIF;*.PNG|All files (*.*)|*.*";
                //"BMP Files (*.BMP)|*.BMP|" +
                //"GIF Files (*.GIF)|*.GIF|" +
                //"JPG Files (*.JPG)|*.JPG|" +
                //"TIF Files (*.TIF)|*.TIF|" +
                //"PNG Files (*.PNG)|*.PNG|" +
                //"EXIF Files (*.EXIF)|*.EXIF|";


            if (fileDialog.ShowDialog() == DialogResult.OK)
            {

                tempFilename = fileDialog.FileName;
                //LoadModel(fileDialog.FileName);
                //mainForm.LoadTexture(fileDialog.FileName);
                //tempTexture = mainForm.LoadTexture(fileDialog.FileName);
                tempName = Path.GetFileNameWithoutExtension(fileDialog.FileName);

                txtName.Text = tempName;

                // TODO: check for valid image



                //if (tempTexture != null)
                //{
                    btnAddToLevel.Enabled = true;
                    txtName.Enabled = true;
                //}
                //else
                //{
                //    btnAddToLevel.Enabled = false;
                //    txtName.Enabled = false;
                //}
            }
        }


        private void btnAddToLevel_Click(object sender, EventArgs e)
        {
            mainForm.AddImageToLibrary(tempName, tempFilename, cmbGroup.Text);

            mainForm.UpdateTreeView();

            Close();
        }
    }
}
